﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace BabyCloudDrives.DesktopApp.Converters
{
    public class ByteConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            float byteSize;
            float convertRate = 1000000f;
            if (parameter != null)
                float.TryParse(parameter.ToString(), out convertRate);
            if (float.TryParse(value.ToString(), out byteSize))
                return byteSize/convertRate;
            return byteSize;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}